
 // Common Definitions
/////////////////////////////////////////////////////////////////////////

#include "sysport.h"


#if !defined(H_COMMON)
#define H_COMMON

namespace Tablebases
{


#if !defined(H_BOOL)
typedef int						bool_t;
#endif

#if !defined(TRUE)
#define TRUE ((bool_t)1)
#endif

#if !defined(FALSE)
#define FALSE ((bool_t)0)
#endif


typedef uint32_t 			sq_t;
typedef uint8_t 			pc_t;
typedef uint32_t			mv_t;
typedef int32_t				tbkey_t;
typedef uint8_t			 	dtm_t;
typedef int64_t				index_t;

// colors of sides
#define BLACK 0
#define WHITE 1
#define CC 1

// database scores 
#define UNKNOWN 0
#define WIN 1
#define LOSS 2
#define DRAW 3

// PDN GameType value of checkers type in tablebase
#define CZECH_CHECKERS			29
#define ENGLISH_CHECKERS		21
#define INTERNATIONAL_CHECKERS	20

#define FILE_HEADER				"DGV"		// Daphne - Gaviota

/*----------------------------------*\
|            CONSTANTS
\*----------------------------------*/

enum TB_mask_values { tb_RESMASK = 3, tb_INFOMASK = 7, tb_PLYSHIFT = 3 };

enum TB_return_values {   
   tb_DRAW = 0,
   tb_WMATE = 1,
   tb_BMATE = 2,
   tb_FORBID = 3,
   tb_UNKNOWN = 7
};

enum TB_pieces    {
   tb_NOPIECE, tb_PAWN, tb_KNIGHT, tb_BISHOP, tb_ROOK, tb_QUEEN, tb_KING
};

enum TB_sides {
   tb_WHITE_TO_MOVE, tb_BLACK_TO_MOVE
};

enum TB_squares {
   tb_A1, tb_B1, tb_C1, tb_D1, tb_E1, tb_F1, tb_G1, tb_H1,
   tb_A2, tb_B2, tb_C2, tb_D2, tb_E2, tb_F2, tb_G2, tb_H2,
   tb_A3, tb_B3, tb_C3, tb_D3, tb_E3, tb_F3, tb_G3, tb_H3,
   tb_A4, tb_B4, tb_C4, tb_D4, tb_E4, tb_F4, tb_G4, tb_H4,
   tb_A5, tb_B5, tb_C5, tb_D5, tb_E5, tb_F5, tb_G5, tb_H5,
   tb_A6, tb_B6, tb_C6, tb_D6, tb_E6, tb_F6, tb_G6, tb_H6,
   tb_A7, tb_B7, tb_C7, tb_D7, tb_E7, tb_F7, tb_G7, tb_H7,
   tb_A8, tb_B8, tb_C8, tb_D8, tb_E8, tb_F8, tb_G8, tb_H8,
   tb_NOSQUARE
};

enum TB_castling {
   tb_NOCASTLE = 0,
   tb_WOO  = 8,
   tb_WOOO = 4,    
   tb_BOO  = 2,
   tb_BOOO = 1
};

enum TB_compression_scheme {
	tb_UNCOMPRESSED, tb_CP1, tb_CP2, tb_CP3, tb_CP4 
};



/*------------ ENUMS ----------------------------------------------------------*/

enum Mask_values {	
					RESMASK  = tb_RESMASK, 
					INFOMASK = tb_INFOMASK, 
					PLYSHIFT = tb_PLYSHIFT  
};

enum Info_values {	
					iDRAW    = tb_DRAW, 
					iWMATE   = tb_WMATE, 
					iBMATE   = tb_BMATE, 
					iFORBID  = tb_FORBID,
		 
					iDRAWt   = tb_DRAW  |4, 
					iWMATEt  = tb_WMATE |4, 
					iBMATEt  = tb_BMATE |4, 
					iUNKNOWN = tb_UNKNOWN,

					iUNKNBIT = (1<<2)
};

/*-------------------------- inherited from a previous maindef.h -----------*/

#define WHITES (1u<<6)
#define BLACKS (1u<<7)

#define NOPIECE 0u
#define PAWN    1u
#define KNIGHT  2u
#define BISHOP  3u
#define ROOK    4u
#define QUEEN   5u
#define KING    6u

#define WH 0
#define BL 1
#define Opp(x) ((x)^1)
#define wK (KING   | WHITES)

/*-------------------
       SQUARES
  -------------------*/

/* from 1-63 different squares posibles   */

/*squares*/
enum SQUARES {
	A1,B1,C1,D1,E1,F1,G1,H1,
	A2,B2,C2,D2,E2,F2,G2,H2,
	A3,B3,C3,D3,E3,F3,G3,H3,
	A4,B4,C4,D4,E4,F4,G4,H4,
	A5,B5,C5,D5,E5,F5,G5,H5,
	A6,B6,C6,D6,E6,F6,G6,H6,
	A7,B7,C7,D7,E7,F7,G7,H7,
	A8,B8,C8,D8,E8,F8,G8,H8,
	NOSQUARE,
	ERRSQUARE = 128
};

/*------------------- end of inherited from a previous maindef.h -----------*/
 
#if !defined(NDEBUG)
#define NDEBUG
#endif
#ifdef DEBUG
#undef NDEBUG
#endif
#include "assert.h"

/*------------------- general DEFINES--------------------------- -----------*/

#define gtbNOSIDE	((unsigned)-1)
#define gtbNOINDEX	((index_t)-1)

/*************************************************\
|
|				COMPRESSION SCHEMES 
|
\*************************************************/

static const char *const Extension[] = {
							 ".cpr.cp0"
							,".cpr.cp1"
							,".cpr.cp2"
							,".cpr.cp3"
							,".cpr.cp4"
							,".cpr.cp5"
							,".cpr.cp6"
							,".cpr.cp7"
							,".cpr.cp8"
							,".cpr.cp9"
};


#define MAX_EGKEYS 7
#define SLOTSIZE 1
#define NOINDEX ((index_t)(-1))

#if defined(SHARED_forbuilding)
	#include "gtb-prob2.h"
#else
	#define mySHARED static
	typedef unsigned char			SQ_CONTENT;
	typedef unsigned int 			SQUARE; 
#endif


}

#endif
